import ViewBase from "./ViewBase";
import LevelProgress from "../LevelProgress";
import Common from "../common/Common";
import UserInfo from "../UserInfo";
import UIManager from "../manager/UIManager";
import Define from "../common/Define";
import WXHelper from "../common/WXHelper";

// Learn TypeScript:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class GameResultCtr extends ViewBase {

    @property(cc.Label)
    textCurSocre: cc.Label = null;

    @property(cc.Label)
    textMaxScore: cc.Label = null;

    @property(cc.Label)
    textFinishProgress: cc.Label = null;

    @property(LevelProgress)
    nodeLevelProgress: LevelProgress = null;

    @property(cc.Node)
    btn_getReward:cc.Node = null;

    @property(cc.Label)
    textRewardCount: cc.Label = null;

    @property(cc.Node)
    nodeClickContinue: cc.Node = null;

    refreshView(isFristRefresh:boolean = false){
        this.nodeLevelProgress.setLevelProgressInfo(Common.curLevel,Common.maxLevelScore);
        this.nodeLevelProgress.setProgress(Common.curLevelScore);

        this.textMaxScore.string = UserInfo.maxScore.toString();
        this.textCurSocre.string = Common.totalShowScore.toString();
        
        let progress =  Math.floor(Common.curLevelScore/ Common.maxLevelScore*100).toString();
        this.textFinishProgress.string = progress + "%已完成";  
        WXHelper.instance.submitScore();
        UserInfo.saveTotalScore();
        this.nodeClickContinue.stopAllActions()
        Common.actionBigSmall(this.nodeClickContinue,0.9,1);
    }

    showActionCallBack(){
        console.log("动作回调");
        WXHelper.instance.showView("GameResult");
    }

    //点击点击事件 //只调用一次
    addEvent(){
        Common.addClickEvent(this.btn_getReward,this.onClick.bind(this));
        Common.addClickEvent(this.node.children[0],this.onClick.bind(this),false);
    }

      //只调用一次
    initView(){
        this.showActionType = Define.left;
    }

    onClick(tag:string){
        if(tag == "btn_getReward"){

        }else{
            UIManager.getInstance().showView(Define.viewMain);
            UIManager.getInstance().showView(Define.viewUpgrade);
            UIManager.getInstance().hideView(Define.viewBattle);
            UIManager.getInstance().hideView(Define.viewGameResult);
            WXHelper.instance.hideView("GameResult");
        }
    }
}
